<?php
/* Should pass the destination URL as parameter
 * returns array of the objects;
 * $arrXml = ExtractXML("http://127.0.0.1/rems_weather.xml");
 */
function getXml($xmlUrl) 
{
	$objXml = simplexml_load_file($xmlUrl);
	$arrXml = toArray($objXml);
	//printNodes($arrXml);
    return $arrXml;
}

function toArray($arrObjData, $arrSkipIndices = array())
{
    $arrData = array();
    
    // if input is object, convert into array
    if (is_object($arrObjData)) 
    {
        $arrObjData = get_object_vars($arrObjData);
    }
    
    if (is_array($arrObjData)) 
    {
        foreach ($arrObjData as $index => $value) 
        {
            if (is_object($value) || is_array($value)) 
            {
            	// recursive call
                $value = toArray($value, $arrSkipIndices); 
            }
            if (in_array($index, $arrSkipIndices)) 
            {
                continue;
            }
            $arrData[$index] = $value;
         }
    }
        return $arrData;
}

/* function printNodes($arr)
	{
		// Key-value pair ($node is the key, $value is the value)
		foreach($arr as $node=>$value) 
		{
			if(is_array($value))
			{
				printNodes($value);
			}
			else 
			{ 
				echo "<strong>" . $node . "</strong>" . "&nbsp;" . $value . "<br />";
			}
		}
	}*/
?>